Skip to content

refactor: streamline Dodo Payments integration and error handling: - #256

Merged
yashdev9274 merged 1 commit into
mainfrom
supercode-cli
Aug 6, 2026
Merged

refactor: streamline Dodo Payments integration and error handling:#256
yashdev9274 merged 1 commit into
mainfrom
supercode-cli

Conversation

@yashdev9274

@yashdev9274 yashdev9274 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Description

  • Removed hardcoded checkout URL logic and replaced it with a fetch request to the billing API for session creation.
  • Enhanced error handling for checkout session failures, providing clearer feedback on Dodo product issues.
  • Consolidated Dodo SDK client initialization into a shared utility function to improve code maintainability.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • bun test passes
  • bun run typecheck passes
  • bun run lint passes (if applicable)

Checklist:

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • New Features

    • Improved plan checkout with server-created sessions and direct checkout redirection.
    • Added clearer checkout error notifications and guidance for unavailable or invalid plans.
    • Standardized payment processing across test and live environments.
  • Bug Fixes

    • Improved payment status, refund, and webhook handling.
    • Checkout now handles missing payment configuration more safely.
  • Chores

    • Updated the server version to 0.1.94.

- Removed hardcoded checkout URL logic and replaced it with a fetch request to the billing API for session creation.
- Enhanced error handling for checkout session failures, providing clearer feedback on Dodo product issues.
- Consolidated Dodo SDK client initialization into a shared utility function to improve code maintainability.
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
supercli Ready Ready Preview Aug 6, 2026 12:52pm
supercli-client Ready Ready Preview Aug 6, 2026 12:52pm
supercli-docs Ready Ready Preview Aug 6, 2026 12:52pm

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PR centralizes Dodo Payments client creation, updates billing routes to use the shared helper, adds invalid-product error handling, and changes studio plan confirmation to create and follow server-generated checkout sessions.

Changes

Dodo billing integration

Layer / File(s) Summary
Shared Dodo client configuration
apps/supercode-cli/server/src/lib/dodo.ts
Adds environment resolution and shared Dodo client creation with API-key and optional webhook-key support.
Billing route integration and error handling
apps/supercode-cli/server/src/api/billing/checkout.ts, apps/supercode-cli/server/src/api/billing/refund.ts, apps/supercode-cli/server/src/api/billing/status.ts, apps/supercode-cli/server/src/api/billing/webhook.ts, apps/supercode-cli/server/package.json
Billing routes use the shared client. Checkout reports invalid products with mode-specific HTTP 400 guidance. The server package version changes to 0.1.94.
Studio checkout session flow
apps/supercode-cli/client/app/studio/page.tsx
Plan confirmation validates the product ID, requests a checkout session from /api/billing/checkout, redirects the current window, and reports errors with toast notifications.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant StudioPage
  participant CheckoutRoute
  participant DodoPayments
  Client->>StudioPage: Confirm selected plan
  StudioPage->>CheckoutRoute: POST user ID and plan ID
  CheckoutRoute->>DodoPayments: Create checkout session
  DodoPayments-->>CheckoutRoute: Return checkout URL
  CheckoutRoute-->>StudioPage: Return checkout URL
  StudioPage->>Client: Redirect current window
Loading

Possibly related PRs

Poem

A rabbit found a checkout trail,
Now server paths replace the tale.
Shared keys guide each Dodo hop,
Invalid plans receive a stop.
The window follows links anew—
“Hop, hop!” says Bunny. “Billing’s true!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: centralized Dodo Payments integration and improved checkout error handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch supercode-cli

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/supercode-cli/server/src/api/billing/checkout.ts (1)

3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the configured absolute import alias for shared server modules.

  • apps/supercode-cli/server/src/api/billing/checkout.ts#L3-L3: Replace ../../lib/dodo with the @/lib/dodo alias.
  • apps/supercode-cli/server/src/api/billing/refund.ts#L3-L3: Replace ../../lib/dodo with the @/lib/dodo alias.
  • apps/supercode-cli/server/src/api/billing/status.ts#L3-L3: Replace ../../lib/dodo with the @/lib/dodo alias.
  • apps/supercode-cli/server/src/api/billing/webhook.ts#L3-L3: Replace ../../lib/dodo with the @/lib/dodo alias.

As per coding guidelines, use absolute imports with @/ path aliases for web-app imports and workspace imports.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/supercode-cli/server/src/api/billing/checkout.ts` at line 3, Replace the
relative Dodo imports with the configured `@/lib/dodo` alias in
apps/supercode-cli/server/src/api/billing/checkout.ts:3-3, refund.ts:3-3,
status.ts:3-3, and webhook.ts:3-3, preserving the existing getDodo and
getDodoEnvironment imports.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/supercode-cli/client/app/studio/page.tsx`:
- Around line 294-297: Protect the checkout flow around the POST request to
/api/billing/checkout by resolving the authenticated request user before any
User query or checkout-session creation, then reject the request when its
authenticated identity does not match req.body.userId. Ensure downstream billing
logic uses only the validated authenticated user identity.

In `@apps/supercode-cli/server/src/lib/dodo.ts`:
- Around line 5-7: Update getDodoEnvironment to accept only the explicit
DODO_MODE values "test" and "live"; map them to "test_mode" and "live_mode"
respectively, and fail closed for unset or any other value instead of defaulting
to live_mode.

---

Nitpick comments:
In `@apps/supercode-cli/server/src/api/billing/checkout.ts`:
- Line 3: Replace the relative Dodo imports with the configured `@/lib/dodo` alias
in apps/supercode-cli/server/src/api/billing/checkout.ts:3-3, refund.ts:3-3,
status.ts:3-3, and webhook.ts:3-3, preserving the existing getDodo and
getDodoEnvironment imports.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: feccf712-1245-4d6e-8395-f3e59d8e7809

📥 Commits

Reviewing files that changed from the base of the PR and between 063931b and 64a0bba.

📒 Files selected for processing (7)
  • apps/supercode-cli/client/app/studio/page.tsx
  • apps/supercode-cli/server/package.json
  • apps/supercode-cli/server/src/api/billing/checkout.ts
  • apps/supercode-cli/server/src/api/billing/refund.ts
  • apps/supercode-cli/server/src/api/billing/status.ts
  • apps/supercode-cli/server/src/api/billing/webhook.ts
  • apps/supercode-cli/server/src/lib/dodo.ts

Comment on lines +294 to +297
const res = await fetch("/api/billing/checkout", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId, planId: confirmingPlan.id }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline apps/supercode-cli/server/src/api/billing/checkout.ts --items all

rg -n -C 10 \
  'router\.(post|use)|req\.body|userId|planId|session|auth|unauthorized|forbidden' \
  apps/supercode-cli/server/src/api/billing/checkout.ts

Repository: yashdev9274/supercli

Length of output: 3782


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== client checkout request context =="
sed -n '270,310p' apps/supercode-cli/client/app/studio/page.tsx

echo
echo "== server api/billing checkout complete =="
cat -n apps/supercode-cli/server/src/api/billing/checkout.ts

echo
echo "== auth/session/ownership patterns in server routes =="
rg -n -C 4 "req\\.user|\\.session|session|auth|authorize|forbidden|unauthorized|middleware|Router\\.use|beforeEach|withAuth|getServerSession|getSession" apps/supercode-cli/server/src/api apps/supercode-cli/server/src | head -n 240

Repository: yashdev9274/supercli

Length of output: 25788


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== server app auth usage =="
sed -n '1,220p' apps/supercode-cli/server/src/index.ts

echo
echo "== auth definition outline and relevant auth usages =="
sed -n '1,260p' apps/supercode-cli/server/src/lib/auth.ts

echo
echo "== server-side auth/session helpers =="
rg -n -C 3 "\.sign\s*\(|\.verify\s*\(|getSession|getServerSession|middleware|router\.use|express-session|cookie-session|better-auth" apps/supercode-cli/server/src

Repository: yashdev9274/supercli

Length of output: 13442


Reject checkout requests where userId does not match the authenticated user.

/api/billing/checkout accepts userId directly from the request body and creates the Dodo checkout using that value. Add middleware that resolves the request user, then compare it with req.body.userId before querying User or creating the checkout session.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/supercode-cli/client/app/studio/page.tsx` around lines 294 - 297,
Protect the checkout flow around the POST request to /api/billing/checkout by
resolving the authenticated request user before any User query or
checkout-session creation, then reject the request when its authenticated
identity does not match req.body.userId. Ensure downstream billing logic uses
only the validated authenticated user identity.

Comment on lines +5 to +7
export function getDodoEnvironment(): DodoEnvironment {
return process.env.DODO_MODE === "test" ? "test_mode" : "live_mode"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject unknown DODO_MODE values.

An unset or invalid value, such as "testing", selects "live_mode". This can make a non-production deployment call live Dodo endpoints. Accept only "test" and "live", then fail closed for other values.

Proposed fix
 export function getDodoEnvironment(): DodoEnvironment {
-  return process.env.DODO_MODE === "test" ? "test_mode" : "live_mode"
+  if (process.env.DODO_MODE === "test") return "test_mode"
+  if (process.env.DODO_MODE === "live") return "live_mode"
+
+  throw new Error('DODO_MODE must be "test" or "live"')
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function getDodoEnvironment(): DodoEnvironment {
return process.env.DODO_MODE === "test" ? "test_mode" : "live_mode"
}
export function getDodoEnvironment(): DodoEnvironment {
if (process.env.DODO_MODE === "test") return "test_mode"
if (process.env.DODO_MODE === "live") return "live_mode"
throw new Error('DODO_MODE must be "test" or "live"')
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/supercode-cli/server/src/lib/dodo.ts` around lines 5 - 7, Update
getDodoEnvironment to accept only the explicit DODO_MODE values "test" and
"live"; map them to "test_mode" and "live_mode" respectively, and fail closed
for unset or any other value instead of defaulting to live_mode.

@yashdev9274
yashdev9274 merged commit 8088548 into main Aug 6, 2026
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant